﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EBSystem.Data;
using EBSystem.SQL;

namespace EBSystem.Pages.UserPages
{
    /// <summary>
    /// UpdateUserAccountInfoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class UpdateUserAccountInfoWindow : Window
    {
        public UpdateUserAccountInfoWindow()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void updateButton_Click(object sender, RoutedEventArgs e)
        {
            UserSourcePage userSourcePage = MainWindow.GetThisMainWindow().mainContentControl.Content as UserSourcePage;
            if (passwordTextBox.Password is not null && passwordTextBox.Password != "")
            {
                SQLConnection.UpdateCustomerPassword(passwordTextBox.Password);
                UserData.userPassword = passwordTextBox.Password;
            }
            if (nickNameTextBox.Text is not null && nickNameTextBox.Text != "")
            {
                SQLConnection.UpdateCustomerNickName(nickNameTextBox.Text);
                UserData.nickName = nickNameTextBox.Text;
                userSourcePage.nickNameTextBox.Text = nickNameTextBox.Text;
            }
            if (emailTextBox.Text is not null && emailTextBox.Text != "")
            {
                SQLConnection.UpdateCustomerEmail(emailTextBox.Text);
                UserData.email = emailTextBox.Text;
                userSourcePage.emailTextBox.Text = emailTextBox.Text;
            }
            if (phoneNumberTextBox.Text is not null && phoneNumberTextBox.Text != "")
            {
                SQLConnection.UpdateCustomerPhoneNumber(phoneNumberTextBox.Text);
                UserData.phoneNumber = phoneNumberTextBox.Text;
                userSourcePage.phoneNumberTextBox.Text = phoneNumberTextBox.Text;
            }
            MessageBox.Show("修改成功");
            Close();
        }
    }
}
